from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Firefox()
# 打开百度首页
url = 'https://www.baidu.com/'
driver.get(url)

sleep(3)
# 点击右上角的登录按钮
driver.find_element(By.CSS_SELECTOR, '#s-top-loginbtn').click()
# 输入用户名和密码
sleep(3)
driver.find_element(By.CSS_SELECTOR, '#TANGRAM__PSP_11__userName').send_keys('admin')
driver.find_element(By.CSS_SELECTOR, '#TANGRAM__PSP_11__password').send_keys('12345678')
# 如果阅读并接受的复选框没有被选中，那么就点击勾选
agree = driver.find_element(By.CSS_SELECTOR, '#TANGRAM__PSP_11__isAgree')
if not agree.is_selected():
    agree.click()
# 点击登录按钮
sleep(3)
driver.find_element(By.CSS_SELECTOR, '#TANGRAM__PSP_11__submit').click()

sleep(3)
driver.quit()